/**
 * This class contains all the necessary HTTP parameters and their respective values related to Tiger Airways (TA)
 * 
 * In a case where TA changed any of their parameters, it should be altered in this class only.
 */

package com.farecrawler.app.airlines;

import java.util.HashMap;
import java.util.Map;

import com.farecrawler.app.constants.Constants;
import com.farecrawler.app.utils.EmailUtils;

public class TigerUtils {
	
	/**
	 * Request parameters
	 */
	public static final String URL = "http://www.tigerairways.com/skylights/cgi-bin/skylights.cgi";
	public static Map<String, String> requestParams = new HashMap<String, String>();
	
	/**
	 * Used by JSoup
	 */
	public static final String TABLE_ELEMENT = "td";
	public static final String ELEMENT_ID_DEPARTURE = "outboundn1";
	public static final String ELEMENT_ID_RETURN = "returnn1";
	
	/**
	 * Misc
	 */
	public static final int FLIGHT_TABLE_CELLS_RANGE = 6;
	public static final String EMAIL_SUBJECT = EmailUtils.DEFAULT_SUBJECT_NAME + " for "+ Constants.TIGER;
	
	/**
	 * RP = Request Parameters
	 */
	public static final String RP_EVENT = "event";
	public static final String RP_MODULE = "module";
	public static final String RP_PAGE = "page";
	public static final String RP_LANGUAGE = "language";
	public static final String RP_MODE = "mode";
	public static final String RP_SID = "sid";
	public static final String RP_REF = "ref";
	public static final String RP_TRAVEL = "travel";
	public static final String RP_FROM1 = "from1";
	public static final String RP_TO1 = "to1";
	public static final String RP_DEPARTDAY1 = "departDay1";
	public static final String RP_DEPARTMONTH1 = "departMonth1";
	public static final String RP_DEPARTDAY2 = "departDay2";
	public static final String RP_DEPARTMONTH2 = "departMonth2";
	public static final String RP_ADULT = "ADULT";
	public static final String RP_DEFAULT_ADULT = "defaultADULT";
	public static final String RP_CHILD = "CHILD";
	public static final String RP_DEFAULT_CHILD = "defaultCHILD";
	public static final String RP_INFANT = "INFANT";
	public static final String RP_DEFAULT_INFANT = "defaultINFANT";
	public static final String RP_TOCITY1 = "toCity1";
	public static final String RP_TOCITY2 = "toCity2";
	public static final String RP_DEPARTDATE1 = "departDate1";
	public static final String RP_DEPARTDATE2 = "departDate2";
	public static final String RP_NUMBERMARKETS = "numberMarkets";
	
	static {
		requestParams.put(RP_EVENT,  "search");
		requestParams.put(RP_MODULE, "SB");
		requestParams.put(RP_PAGE, "SEARCH");
		requestParams.put(RP_LANGUAGE, "EN");
		requestParams.put(RP_MODE, "");
		requestParams.put(RP_SID, "");
		requestParams.put(RP_REF, "");
		requestParams.put(RP_TRAVEL, "2");  									
		requestParams.put(RP_FROM1, "SIN"); 									// user defined
		requestParams.put(RP_TO1, "KUL");  										// user defined
		requestParams.put(RP_DEPARTDAY1, "01");  							// user defined
		requestParams.put(RP_DEPARTMONTH1, "201012");  				// user defined
		requestParams.put(RP_DEPARTDAY2, "05");  							// user defined
		requestParams.put(RP_DEPARTMONTH2, "201012");  				// user defined
		requestParams.put(RP_ADULT, "1");  								
		requestParams.put(RP_DEFAULT_ADULT, "-1");  	
		requestParams.put(RP_CHILD, "0"); 									
		requestParams.put(RP_DEFAULT_CHILD, "-1"); 		
		requestParams.put(RP_INFANT, "0"); 								
		requestParams.put(RP_DEFAULT_INFANT, "-1"); 	
		requestParams.put(RP_TOCITY1, "KUL");                					// user defined
		requestParams.put(RP_TOCITY2, "???");							
		requestParams.put(RP_DEPARTDATE1, "");				
		requestParams.put(RP_DEPARTDATE2, "");				
		requestParams.put(RP_NUMBERMARKETS, "2");		
	}
	
	public static Map<String, String> getRequestParamsMap(String departDay,
			String departYearMonth, String arrivalDay, String arrivalYearMonth,
			String origin, String destination) {
		
		Map<String, String> requestParams = getRequestParams();
		requestParams.put(TigerUtils.RP_FROM1, origin);
		requestParams.put(TigerUtils.RP_TO1, destination);
		requestParams.put(TigerUtils.RP_DEPARTDAY1, departDay);
		requestParams.put(TigerUtils.RP_DEPARTMONTH1, departYearMonth);
		requestParams.put(TigerUtils.RP_DEPARTDAY2, arrivalDay);
		requestParams.put(TigerUtils.RP_DEPARTMONTH2, arrivalYearMonth);
		requestParams.put(TigerUtils.RP_TOCITY1, destination);
		
		return requestParams;

	}
	
	private static Map<String, String> getRequestParams() {
		return requestParams;
	}

}
